import BaseItemView from "../../../cfw/mvc/BaseItemView";
import SleepToyItemModel from "../model/SleepToyItemModel";
import { ItemState } from "../../../cfw/tools/Define";
import BaseItemModel from "../../../cfw/mvc/BaseItemModel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SleepToyItemView extends BaseItemView {


    @property(cc.Sprite)
    ad: cc.Sprite = null;
    @property(cc.Sprite)
    lock: cc.Sprite = null;
    protected model: SleepToyItemModel;

    start() {
        super.start();
        this.updateState()

    }

    onDestroy() {
        super.onDestroy()

    }
    
    addListener() {
        this.eventProxy.on(BaseItemModel.UPDATE_STATE, this.updateState, this)
    }
    isOpen() {
        return this.model.isOpen()
    }

    getOpenLevel() {
        return this.model.getOpenLevel()
    }

    needBuy() {
        return this.model.needBuy()
    }

    updateState() {
        if (!cc.isValid(this.node) || !this.model) {
            return;
        }
        // this.model.setState(ItemState.GOT)
        cc.log(' model ', this.model.getID())
        if (!this.model.needBuy()) {
            if (this.ad) {
                cc.log(' model ', this.model.getID())
                this.ad.node.active = false;
            }
        }
        if (this.model.isOpen()) {
            this.lock.node.active = false
        } else {
            this.lock.node.active = true;
        }
    }

    // update (dt) {}
}
